<template>
  <div class="app-container legal-wrap">
    <dynamic-legal-create ref="dynamicLegal" :type="type" v-model="legalParam" :hide-required-asterisk="false" :rules="rules" :default-list="defaultList" :constructions="comLegalConstruction"/>
    <fixed-pagination>
      <div class="center">
        <!-- <el-button v-if="!reapplyId && !remodifyId" type="info" size="small" class="back-btn empty-btn-style" @click="saveDraft">保存草稿</el-button> -->
        <el-button type="primary" size="small" class="submit-btn" @click="submit()">保存</el-button>
        <el-button type="info" size="small" class="back-btn cancel-btn-style" @click="toBack(10)">返回</el-button>
      </div>
    </fixed-pagination>
  </div>
</template>
<script>
import DynamicLegalCreate from '../module/dynamicLegalCreate';
import AuditProcess from '@/components/Common/auditProcess';
import Title from '@/components/Title';
import Common from '../mixins/common';
import { historyLegalConstruct as legalConstruction } from '../model/legalConstruction';
import { historyLegalRules } from '../model/legalRules';
export default {
  name: 'HistoryLegal',
  components: { DynamicLegalCreate, AuditProcess, Title },
  mixins: [
    Common
  ],
  props: {
    legalDetail: {
      type: Object | String,
      default: () => null
    },
    type: {
      type: String | Number,
      default: ''
    }
  },
  data() {
    return {
      historyLegalRules,
      legalParam: {
        contractInfo: {
          type: '',
          code: '',
          dateRange: [],
          oppCompany: '',
          projectName: '',
          amount: '',
          isYearFrame: '',
          executeDate: '',
          signDate: '',
          stampArchivesDate: '',
          businessTypeName: '',
          post: '',
          particularJob: '',
          otherDec: '',
          attachment: []
        }
      },
      defaultList: {
        'createInfo.proposer': []
      },
      comLegalConstruction: []
    };
  },
  computed: {
    /* comLegalConstruction() {
      return legalConstruction(this.legalConstructionArg);
    }, */
    rules() {
      const tempRules = JSON.parse(JSON.stringify(this.historyLegalRules));
      return tempRules;
    }
  },
  created() {
    this.comLegalConstruction = JSON.parse(JSON.stringify(legalConstruction(this.legalConstructionArg)));
  },
  methods: {
    submit() {
      this.$refs.dynamicLegal.$refs['dynamicLegalCreate'].validate((valid) => {
        if (valid) {
          this.submitFun();
        } else {
          this.$message({
            type: 'warning',
            message: '请检查信息是否填写完整'
          });
          return false;
        }
      });
    },
    submitFun() {
      var timestamp = Date.parse(new Date());
      if (timestamp - this.antiShakeTime < 600) {
        return;
      }
      this.antiShakeTime = timestamp;
      if (this.isSubmit) return;
      const params = JSON.parse(JSON.stringify(this.legalParam));
      if (this.reapplyId) {
        params.submitType = 3;
        params.byReapplyId = this.legalId;
      } else {
        params.submitType = 2;
        if (params.hasOwnProperty('byReapplyId')) delete params.byReapplyId;
      }
      this.remodifyId && (params.byRemodifyId = this.remodifyId);
      const message = this.legalId ? '合同修改成功' : '合同新建成功';
      this.postDataFun(params, message);
    }
  }
};
</script>
<style lang="scss" scoped>
.legal-wrap {
  .footer-btn-wrap {
    display: flex;
    justify-content: center;
  }
  .module-box {
    // margin-bottom: 40px;
    padding-bottom: 32px;
  }
  .audit-process-content {
    min-width: 645px;
    width: calc(100vw * 0.35 + 120px);
    padding: 16px 16px 32px 8px;
    margin-top: 24px;
    margin-bottom: 32px;
  }
}
.empty-btn-style {
  border-color: #406EFF;
  background: #fff;
  color: #406EFF;
  width: 80px;
  padding: 7px 0;
  text-align: center;
}
::v-deep .el-form-item__error {
  padding-top: 2px !important;
}
</style>

